<template>
	<view>
		<view style="background-color: #FFFFFF; text-align: center; padding: 10rpx;">
			<text>车位总数：{{totalnumber}} 剩余车位：{{emptynumber}}</text>
		</view>
		<view>
			<map style="width: 100%; height: 1000px;" :latitude="32.337" :longitude="119.398" :markers="covers"></map>
		</view>
	</view>
</template>

<script>
	import {
		parkqueryurl
	} from '../../common/api.js'
	export default {
		data() {
			return {
				totalnumber: "",
				emptynumber: "",
				latitude: "",
				longitude: "",
				covers: [{
					latitude: "",
					longitude: "",
					iconPath: '/static/location.png',
					width:50,
					height:50
					
				}, {
					latitude: 32.337,
					longitude: 119.398,
					iconPath: '/static/parking.png',
					width:50,
					height:50
				}]
			}
		},
		onShow() {
			this.getSpaceNum();
			this.getLocation();
		},
		methods: {
			getSpaceNum() {

				let jwt = uni.getStorageSync('jwt');
				uni.request({
					url: parkqueryurl,
					header: {
						'jwt': jwt
					},
					success: (res) => {

						let result = res.data;
						console.log(result);
						this.totalnumber = result.data[0].spaceNum;
						this.emptynumber = result.data[0].emptySpaceNum;
						

					},
					fail: () => {
						console.log("网络异常");
					}
				})
			},
			getLocation() {
				uni.getLocation({
					type: 'wgs84',
					success: (res) => {
						this.latitude = res.latitude;
						this.longitude = res.longitude;
						this.covers[0].latitude=res.latitude;
						this.covers[0].longitude=res.longitude;
						console.log("定位成功，经纬度是：" + this.latitude + "," + this.longitude);
					},
					fail: () => {
						console.log("定位失败")
					}
				})
			}
		}
	}
</script>

<style>

</style>
